package com.quanyan.runningriding.web.running;


import com.quanyan.api.APIResponse;
import com.quanyan.runningriding.service.RunMusicService;
import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * RunMusicController
 *
 * @author Tu Chun
 * @date 2016/8/23
 */
@RestController
@RequestMapping(value = "/api/run")
public class RunMusicCollectionOperateController {
    @Autowired
    private RunMusicService runMusicService;

    private Logger logger = LoggerFactory.getLogger(RunMusicCollectionOperateController.class);


    @RequestMapping(value = "/musicCollectionOperate", method = RequestMethod.POST)
    public APIResponse<?> musicCollectionOperate(@RequestBody Map<String, Object> paramMap) {
        String userId = MapUtils.getString(paramMap, "userId");
        Integer musicCollectionId = MapUtils.getInteger(paramMap, "musicCollectionId");
        //操作类型 1喜欢 2播放 3缓存
        Byte operateType = MapUtils.getByte(paramMap, "operateType");
        //操作动作 喜欢 0不喜欢 1喜欢 缓存 0不缓存 1缓存
        Byte operateAction = MapUtils.getByte(paramMap, "operateAction");
        Long playTime = MapUtils.getLong(paramMap, "playTime");

        APIResponse<?> result = runMusicService.musicCollectionOperate(userId, musicCollectionId, operateType, operateAction, playTime);
        if (result.isRet()) {
            return APIResponse.returnSuccess(result.getData());
        } else {
            return APIResponse.returnFail(result.getErrmsg());
        }

    }



}
